package org.example.day02;

/**
 * 第一章节1.9:yield方法，放弃cpu当前的cpu资源，进入就绪状态
 */
public class MyThread4 extends Thread{
    @Override
    public void run() {
        long beginTime = System.currentTimeMillis();
        int count = 0;
        for (int i = 0; i < 500000; i++) {
//            Thread.yield(); //697ms
            count = count + (i+1);
        }
        long endTime = System.currentTimeMillis();
        System.out.println("用时: " + (endTime-beginTime) + "毫秒!");
    }

    public static void main(String[] args) {
        MyThread4 m4 = new MyThread4();
        m4.start();
        for (int i = 0; i < 3; i++) {
            Thread.yield();
            //main 线程放弃cpu执行权之后的状态RUNNABLE
            System.out.println("main 线程放弃cpu执行权力之后的状态" + Thread.currentThread().getState());
        }
    }
}
